package com.sailmi.oss.util;

import io.protostuff.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component
public class DbUtils {
	@Autowired
	private JdbcTemplate jdbcTemplate;
	SnowFlakeIdUtils snowFlakeIdUtils = new SnowFlakeIdUtils(1,30);
	public void saveFileInfo(String fileName,String fileLink,String fileOName,long fileSize){
		long snowId=snowFlakeIdUtils.nextId();
		String sql = "insert into ucs_files(id,file_name,file_link,file_oname,file_size) values(?,?,?,?,?)";
		int result = jdbcTemplate.update(sql, snowId,fileName,fileLink,fileOName,fileSize);
	}

	public void addFileVisitNum(String fileLink){
		String sql="update ucs_files set file_visited = file_visited+1 where file_link=?";
		int result = jdbcTemplate.update(sql, fileLink);
	}

	public void removeFile(String fileLink){
		String sql="delete from ucs_files  where file_link=?";
		int result = jdbcTemplate.update(sql, fileLink);
	}
}
